package org.dao.imp;
import java.util.List;
import org.dao.KcDao;
import org.hibernate.*;
import org.model.Kcb;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class KcDaoImp extends HibernateDaoSupport implements KcDao{
		public Kcb find(String kch) {
			List list=getHibernateTemplate().find("from Kcb where kch=?",kch);
			if(list.size()>0)
				return (Kcb)list.get(0);
			else
				return null;
		}
	public List findAll(int pageNow, int pageSize) {
		Session session=getHibernateTemplate().getSessionFactory().openSession();
		Transaction ts=session.beginTransaction();
		Query query=session.createQuery("from Kcb");
		int firstResult=(pageNow-1)*pageSize;
		query.setFirstResult(firstResult);
		query.setMaxResults(pageSize);
		List list=query.list();
		ts.commit();
		session.close();
		session=null;
		return list;
	}
	public int findKcSize() {
		return getHibernateTemplate().find("from Kcb").size();
	}
}

